<template>
  <div class="cinemaList">
    <div class="cinemaList-top">
      <div class="cinemaList-top-left fz12">
        <div class="search">
          <img src="../../assets/img/cinema-search.png" alt="" />
        </div>
        <input
          type="text"
          placeholder="输入影城名称"
          v-model="message"
          @input="search"
        />
      </div>

      <div class="fz14" @click="back">取消</div>
    </div>

    <div class="cinemaList-wrap fz12" v-show="flag">
      <div class="cinemaList-title fz12">
        <div>离你最近</div>
      </div>
      <div class="cinemaList-wrap-item">
        <div
          class="cinemaList-wrap-item-text mr10 mb10"
          v-for="item in closeCinema"
          :key="item.name"
        >
          {{ item.name }}
        </div>
      </div>
    </div>

    <div v-show="!flag">
      <div v-for="item in placeList" :key="item.name" class="show-style" @click="toCinemaSchedule(item.cinemaId)">{{ item.name }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      message: "",
      flag: true,
      placeList: [],
      timer: null,
      cinemaList:[],
    };
  },
  computed:{
     cityInfo() {
      //刷新时读取上一次的cityId
      return JSON.parse(localStorage.getItem("cityInfo"));
    },
     closeCinema() {
      return this.cinemaList.slice(0, 5);
    },

  },
  created() {
    let that = this;
 
    //  var url="https://m.maizuo.com/gateway?cityId=110100&ticketFlag=1&k=7943003";
    this.axios
      .get(process.env.VUE_APP_BASE_URL, {
        headers: { "X-Host": "mall.film-ticket.cinema.list" },
        params: {
          cityId: that.cityInfo.cityId,
          ticketFlag:0,
          k: 7943003,
        },
      })
      .then(function (res) {
        that.cinemaList = res.data.data.cinemas;
        console.log(res);

      })
      .catch(function (error) {
        console.log(error);
      });
  },

  methods: {
      toCinemaSchedule(cinemaId) {
      this.$router.push({
        path: "/cinema/" + cinemaId,
      });
    },
    back() {
      this.flag = true;
      this.$router.back();
    },
    search() {
      let CinemaList = this.cinemaList;
      let that = this;
      if (this.message) {
        this.flag = false;
        this.placeList = CinemaList.filter(function (item) {
          return item.name.indexOf(that.message) != -1;
        });   
      }else{
        this.placeList = CinemaList;
      }
    },
  },


};
</script>

<style scoped lang="scss">
.show-style{
  margin: 5px 0;
  padding: 5px 0;
  border-bottom: 1px solid rgba(234,234,234);
}
.search {
  line-height: 40px;
  padding-left: 10px;
}
img {
  width: 15px;
  height: 15px;
  position: absolute;
  z-index: 99999999;
  top: 8px;
}
.cinemaList {
  padding: 12px;
}

.cinemaList-top {
  display: flex;
  border-bottom: 1px solid #ededed;
  padding-bottom: 8px;
  align-items: center;
  line-height: 30px;
  position: relative;
}
.cinemaList-top-left {
  flex-grow: 1;
  flex-shrink: 0;
  width: 80%;
}
.cinemaList-top-left input {
  border: none;
  background-color: #f4f4f4;
  border-radius: 3px;
  height: 30px;
  flex-grow: 1;
  flex-shrink: 0;
  width: 80%;

  padding-left: 35px;
}
.cinemaList-title {
  color: #bdc0c5;
  line-height: 13px;
  height: 13px;
  padding: 2px;
  margin: 18px 0;
}
.cinemaList-wrap {
  display: flex;
  justify-content: space-around;
  &-item {
    height: 30px;
    padding: 8px 12px;
    background-color: hsla(0, 0, 95.7%, 0.6);
    border-radius: 3px;
    display: inline-block;
    &-text {
      color: #bdc0c5;
      line-height: 15px;
      display: inline-block;
    }
  }
}
</style>
